
package com.epro.dx.task;

import android.os.AsyncTask;

import com.epro.dx.listenner.MyAsyncTaskListenner;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.weipu.common.constants.Constant;
import com.weipu.common.facade.exception.DxException;
import com.weipu.common.facade.impl.BaseServiceProviderImpl;

import org.json.JSONObject;

import java.util.List;

public class GetRecommendTask extends AsyncTask<Void, Void, String> {
    private MyAsyncTaskListenner myAsyncTaskListenner;

    private long customerId;
    private int dataDisplayPage;

    private GetRecommendsModel respone;

    public GetRecommendTask(long customerId, int dataDisplayPage,
            MyAsyncTaskListenner myAsyncTaskListenner) {
        this.customerId = customerId;
        this.dataDisplayPage = dataDisplayPage;
        this.myAsyncTaskListenner = myAsyncTaskListenner;

    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        if (myAsyncTaskListenner != null) {
            myAsyncTaskListenner.onPostTask(result, respone);
        }
    }

    @Override
    protected String doInBackground(Void... params) {
        try {
            respone = new GetRecommendServiceProviderImpl().getRecommends(customerId,
                    dataDisplayPage);
        } catch (DxException e) {
            return e.getErrCode();
        }
        return "0";
    }

    public class GetRecommendServiceProviderImpl extends BaseServiceProviderImpl {

        public GetRecommendsModel getRecommends(long customerId, int dataDisplayPage)
                throws DxException {

            String url = Constant.GETRECOMMEND_URL + "?customerId=" + customerId
                    + "&dataDisplayPage=" + dataDisplayPage;
            JSONObject jsonObject;
            jsonObject = requestHttpGetData(url);
            GsonBuilder gsonBuilder = new GsonBuilder();
            Gson gson = gsonBuilder.create();
            return gson.fromJson(jsonObject.toString(), GetRecommendsModel.class);
        }

    }

    public static class GetRecommendsModel {
        public boolean IsSuccess;
        public String Status;
        public String Skus;
    }

}
